<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>首期款核销、风险保证金-添加资金</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="capFund_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="caption">
            <span class="title">资金基本信息</span>
        </div>
        <div class="fieldBox col_33">
            <div class="label">资金编号</div>
            <div class="field">
                <a class="link" style="cursor: pointer;" onclick="qyDecompose();"><span id="fundCode">${capFundVO.code}</span></a>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">来款户名</div>
            <div class="field">
                <div class="triggerPop1">
                    <input name="comeName" id="comeName" type="text" class="ui-textbox" value="${capFundVO.comeName}"
                       validate="{required:true,maxlength:64}">
                </div>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">来款账号</div>
            <div class="field">
                <input name="comeCode" id="comeCode" type="text" class="ui-textbox" value="${capFundVO.comeCode}"
                       validate="{required:false,maxlength:21}">
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">来款金额</div>
            <div class="field">
                <input name="amount" id="amount" type="text" class="ui-textbox" value="" disabled="disabled" validate="{required:true,number:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">收款账户</div>
            <div class="field">
                <input name="acceptName" id="acceptName" type="text" class="ui-textbox" value="${capFundVO.acceptName}"
                       validate="{required:true,maxlength:64}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">收款账号</div>
            <div class="field">
                <input name="acceptCode" id="acceptCode" type="text" class="ui-textbox" value="${capFundVO.acceptCode}"
                       validate="{required:false,maxlength:64}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">交易(到账)日期</div>
            <div class="field">
                <input name="acceptDate" id="acceptDate" type="text" class="ui-datepicker"
                       value="${capFundVO.acceptDates}"
                       validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">实际到账日期</div>
            <div class="field">
                <input name="acceptActualDate" id="acceptActualDate" type="text" class="ui-datepicker" value="${capFundVO.acceptActualDates}" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">事业部</div>
            <div class="field">
                <input name="fundBelongOrgCd" id="fundBelongOrgCd" data-value="${capFundVO.fundBelongOrgCd}" validate="{required:true}" placeholder="请选择" ltype="combobox">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <c:if test="${handWayCdNm != null and bizTyp != null}">
            <div class="fieldBox col_33">
                <div class="label">处理方式</div>
                <div class="field">
                    <input name="handWayCdNm" id="handWayCdNm" type="text" class="ui-textbox" value="${handWayCdNm}" readonly="readonly">
                </div>
            </div>
        </c:if>
        <div class="fieldBox col_100">
            <div class="label">摘要</div>
            <div class="field">
                <textarea name="docketRem" id="docketRem" class="ui-textarea l-textarea" value="${capFundVO.docketRem}"
                          rows="4" cols="120" style="width: 99%;" validate="{required:false,maxlength:2000}">${capFundVO.docketRem}</textarea>
                <input type="text" id="fundInputCd" name="fundInputCd" value="1" style="display:none;">
                <input type="text" id="relationPayId" name="relationPayId" value="${capFundVO.relationPayId}" style="display:none;">
                <input type="text" id="cstId" name="cstId" value="${capFundVO.cstId}" style="display:none;">
                <input type="text" id="cstNm" name="cstNm" value="${capFundVO.cstNm}" style="display:none;">
                <input type="text" id="identifyOperator" name="identifyOperator" value="${capFundVO.identifyOperator}" style="display:none;">
                <input type="text" id="identifyOperatorNm" name="identifyOperatorNm" value="${capFundVO.identifyOperatorNm}" style="display:none;">
                <input type="text" id="identifyTime" name="identifyTime" value="${capFundVO.identifyTime}" style="display:none;">
                <%--<input type="text" id="version" name="version" value="${capFundVO.version}" style="display:none;">--%>
                <input type="text" id="fundSourcesCd" name="fundSourcesCd" value="${capFundVO.fundSourcesCd}" style="display:none;">
            </div>
        </div>
    </div>
    <div id="btnDiv" class="btnsBox">
        <span id="saveCapFund_Btn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
    </div>

    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="caption">
            <span class="title">应收列表</span>
        </div>
        <div class="fieldBox col_100">
            <div id="ligergrid_paylist" class="sq-grid"></div>
        </div>
    </div>
</form>
<script>
    var payListGrid=null,capFundId=null;
    $(function () {
    	//事业部
        $("#fundBelongOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        }); 
        $("#capFund_form").ligerForm({
            validate: true,
            onAfterSetFields: function () {
                set_triggerPop1().click(function (event) {
                    var cstId = $("#cstId").val();
                    var cstNm = $("#cstNm").val();
                    var relationPayId = $("#relationPayId").val();
                    $.ligerDialog.SQopen({
                        width: 950,
                        height: 490,
                        title: '选择资金列表',
                        url: '<%=path%>/capital/capFund/toChooseFund.do?type=1&bizTypCd=2&relationPayId=' + relationPayId + '&cstId=' + cstId + '&cstNm=' + cstNm,
                        fixButtons: true,
                        allowClose: false,
                    });
                });
            }
        });
        //给输入框添加三点...并返回此节点，可用于绑定事件
        function set_triggerPop1() {
            var $triggerBtn = $('<div class="l-text-popup"><div class="l-trigger"><div class="l-trigger-icon"></div></div></div>');
            $('.triggerPop1 .l-text').append($triggerBtn);
            return $triggerBtn;
        };

        liger.get("fundBelongOrgCd").setData(${fundBelongOrgCdList});
        capFundId = "${capFundVO.id}";//主键ID
        if(capFundId){
            //修改时如果资金可用金额已变动，就不能继续修改了 2017-02-13
            var usedAmt="${capFundVO.usedAmount}";
            if(usedAmt>0){
                $("#btnDiv").hide();
            }
        }

        var amount='${amount}';
        if(amount){
            $("#amount").val(amount);
        }
        /*支付表明细*/
        payListGrid = $("#ligergrid_paylist").ligerGrid({
            columns: [
                {display: '支付表', name: 'paySchNo', minWidth: 100 },
                {display: '应收项目', name: 'feeTypCdNm', minWidth: 100},
                {display: '应收金额', name: 'feeAmt', minWidth: 100,align: 'right',
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.feeAmt/100);
                    }
                },
                {display: '已收金额', name: 'paidUpAmt', minWidth: 100,align: 'right',
                    render:function(rowdata,index,value){
                        if(value){
                            return '&yen;'+FormatMoney(rowdata.paidUpAmt/100);
                        }
                    }
                },
                /*{display: '应收日期', name: 'payDt', minWidth: 100,render:renderDate},*/
                {display: '制作人', name: '', minWidth: 100,render:function (rowdata,index,value) {
                    return '${vfUsrNm}';
                }},
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            heightDiff: -2,
            isScroll: false,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
        });

        //首期款明细
        <c:if test="${paySchList!=null}">
            var jsonObj = {};
            jsonObj.rows = ${paySchList};
            payListGrid.set({data: jsonObj});
        </c:if>

        
        var accDialog=null;
        $("#acceptName").focus(function(event) {
            accDialog=$.ligerDialog.SQopen({
                url: "<%=path%>/system/sysBkAccInfo/toChooseListPage.do",
                width: 800,
                height: 400,
                title: "选择收款账户"
            });
        });

        /*保存*/
        $("#saveCapFund_Btn").click(function (event) {
            var form = liger.get("capFund_form");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = form.getData();
            //data["amount"]=parseFloat($("#amount").val()*100);
            $.ligerDialog.hide();
            var _url;
            if (capFundId == '') {//新增
                _url = '<%=path%>/capital/capFund/add.do';
            } else {//修改
                _url = '<%=path%>/capital/capFund/modify.do?id=' + capFundId;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: _url,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        capFundId=msg.data;
                        $('#fundcode').text('ZJ'+capFundId);
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });

        /*关闭*/
        $("#closeBtn").click(function (event) {
            //frameElement.dialog.close();
        });
    });

    //查看分解单
    function qyDecompose(){
        if(!capFundId){
            return;
        }
        Add_navTab('toDecomDtlPage_'+capFundId, "分解单查看", '<%=path%>/capital/capFund/toDecomDtlPage.do?fundId='+capFundId, null);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
</script>
</body>
</html>
